package cn.zshprint.serein.controller;

import cn.zshprint.serein.entity.Permission;
import cn.zshprint.serein.entity.PermissionRoleRelation;
import cn.zshprint.serein.entity.User;
import cn.zshprint.serein.pojo.ResultBean;
import cn.zshprint.serein.service.PermissionRoleRelationService;
import cn.zshprint.serein.service.PermissionService;
import cn.zshprint.serein.service.RoleUserRelationService;
import cn.zshprint.serein.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Permission)表控制层
 *
 * @author makejava
 * @since 2021-08-03 11:10:14
 */
@RestController
@RequestMapping("permission")
public class PermissionController {
    /**
     * 服务对象
     */
    @Resource
    private PermissionService permissionService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne/{id}")
    public ResultBean<Permission> selectOne(@PathVariable Integer id) {
        return new ResultBean<Permission>(permissionService.selectOne(id));
    }

    @GetMapping("selectAll")
    public ResultBean<List<Permission>> selectAll() {
        return new ResultBean<List<Permission>>(permissionService.selectAll());
    }

    @GetMapping("selectByUser/{username}")
    public ResultBean<List<Permission>> selectByUser(@PathVariable String username) {
        return new ResultBean<List<Permission>>(permissionService.selectByUser(username));
    }

    @PostMapping("saveOne")
    public ResultBean<Integer> saveOne(@RequestParam("desc") String description) {
        return new ResultBean<Integer>(permissionService.saveOne(description));
    }

    @DeleteMapping("deleteOne/{id}")
    public ResultBean<Integer> deleteOne(@PathVariable Integer id) {
        return new ResultBean<Integer>(permissionService.deleteOne(id));
    }
}